<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录--layui后台管理模板</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/asset/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/asset/css/global.css" media="all"/>

    <style>
        .gap_top {
            margin-top: 15px;
        }

        .gap_bottom {
            margin-bottom: 15px;
        }

    </style>
</head>
<body>

<div class="video_mask"></div>
<div class="login">
    <h1>配置管理登录</h1>
    <form class="layui-form">
        <div class="layui-form-item">
            <input class="layui-input" name="username" placeholder="用户名" lay-verify="required" type="text"
                   autocomplete="off">
        </div>
        <div class="layui-form-item">
            <input class="layui-input" name="password" placeholder="密码" lay-verify="required" type="password"
                   autocomplete="off">
        </div>
        <!--<div class="layui-form-item form_code">-->
        <!--<input class="layui-input" name="code" placeholder="验证码" lay-verify="required" type="text"-->
        <!--autocomplete="off">-->
        <!--<div class="code"><img src="/asset/images/code.jpg" width="116" height="36"></div>-->
        <!--</div>-->
        <div class="gap_bottom">
            <button class="layui-btn login_btn" lay-submit="" lay-filter="login">登录</button>
        </div>
        <hr class="layui-bg-orange">
        <div class="gap_top">
            <a class="layui-btn layui-btn-normal login_btn" href="/user/register.html">注册</a>
        </div>

    </form>
</div>
<script type="text/javascript" src="/asset/layui/layui.js"></script>
</body>
<script>

    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            $ = layui.jquery;

        //登录按钮事件
        form.on("submit(login)", function (data) {

            $.ajax({
                url: "/user/login",
                type: "POST",
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (_data) {
                    console.log(_data)
                    if (_data.code != 0) {
                        layer.alert('请求失败!<br>' + _data.message, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        })
                        return false

                    }
                    location.href = "/"

                },
                error: function (xhr, type) {
                    layer.msg("请求失败");
                }
            })

            return false;
        })

        layer.msg(findGetParameter("msg"));

    })


    function findGetParameter(parameterName) {
        var result = null,
            tmp = [];
        location.search
            .substr(1)
            .split("&")
            .forEach(function (item) {
                tmp = item.split("=");
                if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
            });
        return result;
    }

</script>
</html>